#!/bin/sh

render () {
	state=$(doas iwctl station wlan0 show | grep State | tr -s ' ' | cut -d ' ' -f3)
	case $state in
		connected) printf "<span color='#1c9867'>█</span>" ;;
		connecting) printf "<span color='#1c9867'>▒</span>" ;;
		disconnected) printf "<span color='#1c9867'>░</span>" ;;
	esac
}

if [ -e /tmp/swaybar/pipe ]
then
	printf "network|%s\n" "$(render)" >/tmp/swaybar/pipe
fi
if [ "$1" = '-1' ]
then
	exit
fi

/sbin/ip monitor address | while read -r _
do
	printf "network|%s\n" "$(render)" >/tmp/swaybar/pipe
done
